
from model.entitys import get_sync_db
from service.apiService import ApiService
from service.caseService import update_result, update_whether_by_web

class BaseCaseService:

    def __init__(self):
        self.session = get_sync_db()
        self.api = ApiService()
        self.num = {
            "pass_number": 0,
            "fail_number": 0
        }

    def run_case(self, case: dict):
        del case['case_group_id']
        del case['remarks']
        del case['createdAt']
        del case['updatedAt']

        try:
            result, resp, element = self.api.implement_case(**case)

        except Exception as e:
            self.num["fail_number"] = self.num["fail_number"] + 1
            update_whether_by_web(self.session, e, case["id"], "fail")

            raise AssertionError

        else:
            update_result(self.session, self.api, case["assert_info"], case["expected_results"],
                          case["actual_result_template"],
                          result, case["id"], self.num, resp,
                          element, True)













































